-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up TopoSort by 2.7-3.3x. #3946
Conversation
…ort::sort_worker is 11-12x faster. Overall, the complete sequence of building the graph and sorting is about 2.5-3x faster. The overall impact in e.g. the replace_const_cells optimization pass is a ~25% speedup. End-to-end impact on our synthesis flow is about 3%.
What are your thoughts on this PR? I could back out the unrelated formatting changes in utils.h, if so desired. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems good to me.
OK, I got rid of the needless formatting changes in |
It looks like the test |
… node, not an edge in glift and flatten. Add back statement that inserts nodes in order in opt_expr.cc.
Fixed. BTW: I realized that this code is somewhat brittle, since the sort order in |
OK, It finally passed. :-) PTAL. |
…TopoSort time overall by ~10%.
Trimmed a little fat off my implementation of |
@Ravenslofty any updates from today's meeting? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code got less readable, unfortunately, but I suppose that's the price we ought to pay. Thanks @rmlarsen!
We could opt for a non-recursive algorithm (a code example I have at hand), but that might not be producing the sort order code users expect, especially if they supply the |
Thanks! Yeah, I've sometimes written it non-recursively, but in the profile it doesn't look like the recursion is a problem. One potential issue for large graphs is max allowed stack size, of course. |
The main implementation in
TopoSort::sort_worker
is 11-12x faster. Overall, the complete sequence of building the graph and sorting is about 2.7-3.3x faster for the circuit I am working on. The overall impact in e.g. the replace_const_cells optimization pass is a ~35% speedup. End-to-end impact on our synthesis flow is about 3.3%.Flame graph, zoomed on replace_const_cells, before:
Flame graph, zoomed on replace_const_cells, after:
Topdown view before:
Topdown view after: